package compiler.nonterminals;

import compiler.HowlToken;
import compiler.HowlType;
import compiler.TokenReader;
import compiler.exceptions.HowlParserException;
import compiler.terminals.DataProvider;
import compiler.terminals.FeedName;

/**
 * This class represents deregister statements, as in:
 * 
 * deregister FeedName DataProvider
 * 
 * @author Sarah Mount <s.mount@wlv.ac.uk>
 * @version 16 Dec 2009
 * @see compiler.terminals.FeedName
 * @see compiler.terminals.DataProvider
 */
public class DeregisterStmt extends HowlToken {

	private FeedName feedname;
	private DataProvider dataprovider;

	public DeregisterStmt(TokenReader tokenReader) {
		super(tokenReader);
	}

	@Override
	public String codeGenerate() {
		return "DELETE " + this.dataprovider.codeGenerate() + " FROM "
				+ this.feedname.codeGenerate() + ";";
	}

	@Override
	public HowlToken parse() throws HowlParserException {
		String command = this.tokenReader.consumeToken();
		if (!"deregister".equals(command))
			throw new HowlParserException(this.tokenReader.getStatement(),
					this.tokenReader.getCharNo());

		this.feedname = (FeedName) new FeedName(this.tokenReader).parse();
		this.dataprovider = (DataProvider) new DataProvider(this.tokenReader)
				.parse();
		return this;
	}

	@Override
	public String toString() {
		return "deregister " + this.feedname.toString() + " "
				+ this.dataprovider.toString() + ";";
	}

	/**
	 * @return the feedname
	 */
	public FeedName getFeedname() {
		return feedname;
	}

	/**
	 * @param feedname the feedname to set
	 */
	public void setFeedname(FeedName feedname) {
		this.feedname = feedname;
	}

	/**
	 * @return the dataprovider
	 */
	public DataProvider getDataprovider() {
		return dataprovider;
	}

	/**
	 * @param dataprovider the dataprovider to set
	 */
	public void setDataprovider(DataProvider dataprovider) {
		this.dataprovider = dataprovider;
	}

}